package com.ruoyi.system.mapper;

import java.util.List;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.system.domain.BriefReport;
import com.ruoyi.system.domain.ReportBriefElement;
import com.ruoyi.system.domain.ReportElement;
import org.apache.ibatis.annotations.*;

/**
 * 简报模板Mapper接口
 *
 * @author ruoyi
 * @date 2021-06-07
 */
public interface BriefReportMapper {
    /**
     * 查询简报模板
     *
     * @param briefReportId 简报模板ID
     * @return 简报模板
     */
    public BriefReport selectBriefReportById(Long briefReportId);

    /**
     * 查询简报模板列表
     *
     * @param briefReport 简报模板
     * @return 简报模板集合
     */
    public List<BriefReport> selectBriefReportList(BriefReport briefReport);

    /**
     * 新增简报模板
     *
     * @param briefReport 简报模板
     * @return 结果
     */
    public int insertBriefReport(BriefReport briefReport);

    /**
     * 修改简报模板
     *
     * @param briefReport 简报模板
     * @return 结果
     */
    public int updateBriefReport(BriefReport briefReport);

    /**
     * 删除简报模板
     *
     * @param briefReportId 简报模板ID
     * @return 结果
     */
    public int deleteBriefReportById(Long briefReportId);

    /**
     * 批量删除简报模板
     *
     * @param briefReportIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteBriefReportByIds(Long[] briefReportIds);


    public int batchBriefElement(List<ReportBriefElement> list);


    @Delete("<script>delete from report_brief_element where brief_id in <foreach collection = 'briefReportIds' item ='id' index ='index' open='(' close=')' separator=','>#{id}</foreach></script>")
    public int deleteReportBriefElementByIds(@Param("briefReportIds") Long[] briefReportIds);


    @Update("UPDATE brief_report SET is_default = (\n" +
            "    CASE brief_report_id WHEN #{briefReportId} THEN 1  \n" +
            "\t\tELSE 0\n" +
            "    END)")
    public int setDefaultTemplate(@Param("briefReportId") Long briefReportId);


    @Select("select element_id  from report_brief_element where brief_id = #{briefReportId} " +
            "order by sequence asc "
    )
    List<Long> selectElementByReportId(@Param("briefReportId") Long briefReportId);



    @Select("SELECT\n" +
            "\te.*,r.show_name,r.text\n" +
            "FROM\n" +
            "\treport_brief_element r\n" +
            "\tLEFT JOIN report_element e ON r.element_id = e.id \n" +
            "WHERE\n" +
            "\tr.brief_id = #{briefReportId} \n" +
            "ORDER BY\n" +
            "\tr.sequence ASC")
    @Results({
            @Result(column = "show_text", property = "showText"),
            @Result(column = "element_style_icon", property = "elementStyleIcon"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "show_name", property = "showName"),
    })
    List<ReportElement> selectElementsByReportId(@Param("briefReportId") Long briefReportId);


    @Select("select *  from brief_report where is_default = 1")
    @Results({@Result(column = "brief_report_id", property = "briefReportId"),
            @Result(column = "report_name", property = "reportName"),
            @Result(column = "template_name", property = "templateName"),
            @Result(column = "is_default", property = "isDefault"),
            @Result(column = "is_system", property = "isSystem"),
            @Result(column = "model_from", property = "modelFrom"),
            @Result(column = "model_image", property = "modelImage"),
            @Result(column = "model_title", property = "modelTitle"),
            @Result(column = "font_family", property = "fontFamily"),
            @Result(column = "font_family_title", property = "fontFamilyTitle"),
            @Result(column = "font_family_title_second", property = "fontFamilyTitleSecond"),
            @Result(column = "font_weight", property = "fontWeight"),
            @Result(column = "font_weight_title", property = "fontWeightTitle"),
            @Result(column = "font_weight_title_second", property = "fontWeightTitleSecond"),
            @Result(column = "font_size_title", property = "fontSizeTitle"),
            @Result(column = "font_size_paragraph", property = "fontSizeParagraph"),
            @Result(column = "font_size_content", property = "fontSizeContent"),
            @Result(column = "font_title_color", property = "fontTitleColor"),
            @Result(column = "publishing_department", property = "publishingDepartment"),
    })
    BriefReport getDefaultTemplate();
}
